package com.xunlai.infra.permission.business.dao.repository;

import com.xunlai.infra.permission.business.dao.entity.RouteTemplate;
import com.xunlai.infra.permission.business.dao.entity.vo.RouteTemplateCountVo;
import com.xunlai.infra.permission.storage.repository.BaseAllRoundRepository;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author liang
 * @date 8/22/23 4:11 PM
 */
@Transactional(rollbackFor = Exception.class)
public interface RouteTemplateRepository extends BaseAllRoundRepository<RouteTemplate,Long> {

    @Query("select route_template,count(DISTINCT id) as routeCount,count(DISTINCT route_subject) as subjectCount  from travel_route_info where route_template in (:ids) GROUP BY route_template ;")
    List<RouteTemplateCountVo> selectRouteCountByTemplateIn(@Param("ids") Set<Long> templateIds);

    @Query("select route_template,count(DISTINCT id) as routeCount,count(DISTINCT route_subject) as subjectCount  from travel_route_info where route_template in (:ids) and create_user = :createUser GROUP BY route_template ;")
    List<RouteTemplateCountVo> selectRouteCountByTemplateInAndCreateUser(@Param("ids") Set<Long> templateIds,@Param("createUser") Long createUser);
}
